var table;
var layer;
layui.use('table',function(){
    table=layui.table;
    table.on('checkbox(test)', function(obj){
        $("#course_id").val(obj.data.course_id)
        console.log(obj); //当前行的一些常用操作集合
        console.log(obj.checked); //当前是否选中状态
        console.log(obj.data); //选中行的相关数据
        console.log(obj.type); //如果触发的是全选，则为：all，如果触发的是单选，则为：one
    });
    sousuo();
});

//弹出检索页面
function retrieve() {
    var id=$("#course_id").val();
    $.ajax({
        url:"/Teacher/selectTable1",
        type:"get",
        dataType:"json",
        data:{"id":id},
        success:function(data){
            aaa(data)
        }
    })
}
layui.use('layer',function(){
    layer=layui.layer;

//刷新
    $("#refresh").click(function () {
        location.reload();
    })
});

function aaa(data) {
    console.log(data.obj)
    layer.open({
        type : 2,//弹出层的类型
        id:1,
        title : "<div style='color:#666666;font-weight: 600;background: #F8F8F8;'>教师详情</div>",
        area : [ '1000px', '700px' ],
        maxmin: true,
        shade : 0,
        offset: 'auto',
        content :"ProductRetrieve.html",
        success:function(layero,index){
            var obj=layero.find('iframe').contents();
            obj.find("input[name=course_name]").val(data.obj[0].course_name);
            obj.find("input[name=create_date]").val(data.obj[0].create_date);
            obj.find("input[name=create_user]").val(data.obj[0].create_user);
            obj.find("input[name=course_nprice]").val(data.obj[0].course_nprice);
            obj.find("input[name=course_primary]").val(data.obj[0].course_primary);
            obj.find("input[name= categroy_name]").val(data.obj[0]. categroy_name);
            obj.find("input[name= like_num]").val(data.obj[0]. like_num);
            obj.find("input[name=collect_num]").val(data.obj[0].collect_num);
            obj.find("input[name=content]").val(data.obj[0].content);
            obj.find("input[name=course_intro]").val(data.obj[0].course_intro);
            obj.find("input[name=remarks]").val(data.obj[0].remarks);
        }
    });
    window.layer_1=layer;
}




function sousuo(){
    var name=$("#name").val();
    var course=$("#course").val();
    var price=$("#price").val();
    $.ajax({
        url:"/Teacher/selectTable",
        type:"post",
        dataType:"json",
        data:{"name":name,"course":course,"price":price},
        success:function(data){
           getTable(data.obj);
        }
    })
}
function getTable(data) {
    table.render({
        elem: "#table_id",
        title: "表格",
        limit: 10,
        page: true,
        data:data,
        cols: [[
            {type: 'checkbox', fixed: 'left'},
            {field: 'course_id', title: '编号', fixed: 'center', width: 80},
            {field: 'url', title: '课程图片', fixed: 'center', width: 120, templet: function (data) {
                    return "<div><img src=http://localhost:8089/courseImg/fengmian.png ></div>";
                }
            },
            {field: 'course_name', title: '课程名称', fixed: 'center', width: 100},
            {field: 'course_price', title: '价格',fixed: 'center', width: 100},
            {field: 'course_no', title: '分类编号', width: 100},
            {field: 'like_num', title: '排序', width: 100},
            {field: 'course_primary', title: '分类', width: 100},
            {field: 'product_sate', title: '审核状态', width: 120},
            {field: '', title: '操作', width: 115, templet: function (d) {
                    return "<span id='render' onclick='shenhe()'>查看</span>"+
                        "<span id='bianji' onclick='bianji()'>编辑</span>" +"<br/>"+"" +
                        "<span id='render' onclick='rizhi()'>日志</span>"+"" +
                        "<span id='bianji' onclick='shanchu()'>删除</span>";
                }
            }
        ]]
    });
}
function shenhe(){
    layer.open({
        type : 2,//弹出层的类型
        id:1,
        title : "<div style='color:#666666;font-weight: 600;background: #F8F8F8;'>课程详情</div>",
        area : [ '1000px', '700px' ],
        maxmin: true,
        shade : 0,
        offset: 'auto',
        content :"ProductRetrieve.html",
        success:function(layero,index){

        }
    });
}
function bianji(){
    layer.open({
        type : 2,//弹出层的类型
        id:1,
        title : "<div style='color:#666666;font-weight: 600;background: #F8F8F8;'>课程编辑</div>",
        area : [ '1000px', '700px' ],
        maxmin: true,
        shade : 0,
        offset: 'auto',
        content :"ProductRetrieve.html",
        success:function(layero,index){

        }
    });
}
function rizhi(){
    layer.open({
        type : 2,//弹出层的类型
        id:1,
        title : "<div style='color:#666666;font-weight: 600;background: #F8F8F8;'>课程编辑</div>",
        area : [ '1000px', '700px' ],
        maxmin: true,
        shade : 0,
        offset: 'auto',
        content :"ProductRetrieve.html",
        success:function(layero,index){

        }
    });
}
function shanchu(){

}